(function () {
    init();

    function init() {
        initTreeGrid();
        initVue();
    }

    function initTreeGrid() {
        var urlVar = '/ruofeng/app/privilege/resource?id=0&deep=tree';//查找node=0,根节点的所有孩子
        $('#tg').treegrid({
            iconCls: 'icon-ok',
            toolbar: "#toolbar",
            rownumbers: true,
            animate: true,
            collapsible: true,
            fitColumns: true,
            method: 'get',
            idField: 'id',
            lines: true,
            treeField: 'name',
            showFooter: true
        });
        ajaxTreeGridData(urlVar, function (response) {
            $('#tg').treegrid("loadData", response.data)
        })
    }

    function ajaxTreeGridData(url, callback) {
        $.getJSON(url, function (response) {
            callback(response);
        })
    }


    function initVue() {
        var config = {
            el: "#app",
            data: function () {
                return {
                    dialogTitle: "",
                    dialogSrc: "",
                    dialogVisible: false,
                }
            }
        }
        window.vue=new Vue(config)
    }
})()

/**
 * 操作栏的按钮绘制
 * @param value
 * @returns {string}
 */
function operateFmt(value, row, index) {
    return '<button onclick="editThisRow(' + row.id + ')">编辑</button>' +
        '<button onclick="appendChildren(' + row.id + ')">新增</button>'
}

function editThisRow(id) {
    parent.vue.$data.dialogTitle = "资源编辑"
    parent.vue.$data.dialogSrc = "resourceInfo.html?id=" + id;
    parent.vue.$data.activeName = "second";
}

function appendChildren(id) {
    parent.vue.$data.dialogTitle = "新增资源"
    parent.vue.$data.dialogSrc = "resourceInfo.html?parentId=" + id;
    parent.vue.$data.activeName = "second";
}

